package com.kashi.mapper;

import com.kashi.pojo.Card;
import com.kashi.pojo.Collection;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CollectionMapper {

    //获取合集列表
    @Select("SELECT userId,name,numOfCard,creatTime,updateTime FROM collections where userId = #{userId}")
    List<Collection> getCollections(Integer userId);

    //创建合集
    @Insert("INSERT INTO collections (userId,name,numOfCard,createTime,updateTime) VALUES (#{userId}, #{name},#{numOfCard},#{creatTime},#{updateTime})")
    void insert(Collection collection);

    //删除合集
    @Delete("DELETE FROM collections WHERE id = #{id}")
    void delete(Integer id);

    //获取合集内容
    @Select("SELECT cardList FROM collections where id = #{id}")
    List<Card> getContent(Integer id);

    //编辑合集
    @Update("UPDATE collections SET" +
            "<if test='newName != null'> name = #{newName} </if>" +
            "<if test='newList != null'> cardList = #{newList} </if>" +
            " WHERE id = #{id}")
    void update(Integer id,String newName,List<Card> newList);
}
